package com.zx.core.utils;

import com.alibaba.fastjson2.JSON;
import com.zx.core.wrapper.ObjectWrapper;


/**
 * <p>
 * description:  <br>
 * create: 2024-10-11 20:17
 * </p>
 *
 * @author zhou  xun
 */
public class JsonStrUtils {
    /**
     * 检查参数是否正确
     *
     * @param jsonStr     json字符串
     * @param targetClass 目标类
     * @param <T>         泛型目标类
     * @return {@link ObjectWrapper <T>}
     * @author zhou  xun
     * @since 2024-10-11
     */
    public static <T> ObjectWrapper<T> checkParseObject(String jsonStr, Class<T> targetClass) {
        ObjectWrapper<T> result = new ObjectWrapper<>();
        T parseObject;
        try {
            parseObject = JSON.parseObject(jsonStr, targetClass);
            result.setData(parseObject);
        } catch (Exception e) {
            result.fail("参数解析异常:" + jsonStr);
        }
        return result;
    }
}
